package com.aaie.gru.interview.service.impl;

import com.aaie.gru.interview.entity.GruSysInterview;
import com.aaie.gru.interview.entity.GruSysInterviewDto;
import com.aaie.gru.interview.entity.GruSysInterviewVo;
import com.aaie.gru.interview.mapper.GruSysInterviewMapper;
import com.aaie.gru.interview.service.IGruSysInterviewService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lvxing
 * @since 2019-08-09
 */
@Service
public class GruSysInterviewServiceImpl extends ServiceImpl<GruSysInterviewMapper, GruSysInterview> implements IGruSysInterviewService {

    @Resource
    GruSysInterviewMapper gruSysInterviewMapper;

    @Override
    public IPage<GruSysInterviewVo> getGruSysInterviewVoList(GruSysInterviewDto param) {
        // 定义分页
        Page<GruSysInterviewVo> page = new Page<>(param.getCurrent(), param.getSize());
        // 查询条件
        QueryWrapper<GruSysInterview> queryWrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(param.getSearch())) {
            queryWrapper.and(qw -> qw.like("i.interview_status", param.getSearch())
                    .or().like("i.interview_date", param.getSearch()));
        }

        if(StringUtils.isNotEmpty(param.getInterviewGuardianId())){
            queryWrapper.eq("interview_guardian_id",param.getInterviewGuardianId());
        }

        if(StringUtils.isNotEmpty(param.getInterviewStuStatus())){
            queryWrapper.eq("i.interview_stu_status",param.getInterviewStuStatus());
        }
        // 按更新时间倒叙排序
        queryWrapper.orderByDesc("i.update_time_sort");
        return gruSysInterviewMapper.selectGruSysInterviewVoList(page, queryWrapper);
    }
}
